import  http =require( "http")
import  url=require("url")
import {ParsedUrlQuery} from "querystring";

//使用装饰器方法自动配置请求处理器
export function HttpHandleAttr(url: string)
{
    return function (constructor: any)
    {
        console.log(`注册处理器:${url}`);
        HandleManager.AddHandle(url, new constructor());
    }
}
export interface IHandle
{
    onGet(query: ParsedUrlQuery, res: http.ServerResponse): Promise<void>
    onPost(req: http.IncomingMessage, res: http.ServerResponse): Promise<void>;
}
export class HandleManager
{
    public static GetHandle(path: string): IHandle
    {
        return HandleManager.handles[path];
    }
    public static AddHandle(path: string, handle: IHandle)
    {
        HandleManager.handles[path] = handle;
    }
    protected static handles: { [id: string]: IHandle } = {};//字典用來存放請求處理器，請求處理器不應該保存内部狀態，原來每次都new，意義不明
}